var largestDivisibleSubset = function(arr) {
    arr.sort((a, b) => a - b)
    let cache = {}
    cache[arr[arr.length - 1]] = [arr[arr.length - 1]]
    let maxIndex = arr[arr.length - 1]
    let maxItem = cache[arr[arr.length - 1]]

    for (let i = arr.length - 2; i >= 0; i--) {
        const item = arr[i]
        let max = []
        for (let j = i + 1; j < arr.length; j++) {
            const secItem = arr[j]
            if (secItem % item === 0) {
                if (max.length < cache[secItem].length) {
                    max = cache[secItem]
                }
            }
        }
        let temp = max.map((item, index) => {
            return item
        })
        temp.push(item)
        cache[item] = temp
        if (temp.length > maxItem.length) {
            maxItem = temp
            maxIndex = item
        }
    }
    return maxItem.reverse()
};
let arr = []
for (let i = 0; i < 1001; i++) {
    arr.push(i)
}
const fs = require('fs')
const path = require('path')
let file = path.resolve(__dirname, './file.txt')
    // 异步写入数据到文件
fs.writeFile(file, JSON.stringify(arr), { encoding: 'utf8' }, err => {})
console.log(largestDivisibleSubset(arr))